(function($, owner) {
    /**
     * 用户登录
     **/
    owner.change = function(loginInfo, callback) {
        callback = callback || $.noop;
        loginInfo = loginInfo || {};
        loginInfo.phone = loginInfo.phone || '';
        loginInfo.pass = loginInfo.pass || '';
        loginInfo.code = loginInfo.code || '';

        if (loginInfo.phone.length != 11) {
            return callback('账号请输入11位手机号');
        }
        if (loginInfo.pass.length < 6) {
            return callback('密码最短为 6 个字符');
        }
        if (loginInfo.code.length < 4) {
            return callback('验证码最短为 4 个字符');
        }
       /* var users = JSON.parse(localStorage.getItem('$users') || '[]');
        var authed = users.some(function(user) {
            return loginInfo.account == user.account && loginInfo.password == user.password;
        });*/
        if (true) {
            mui.alert('修改成功');
        } else {
            return callback('用户名或密码错误');
        }
    };

    var checkEmail = function(email) {
        email = email || '';
        return (email.length > 3 && email.indexOf('@') > -1);
    };

    /**
     * 找回密码
     **/
    owner.forgetPassword = function(email, callback) {
        callback = callback || $.noop;
        if (!checkEmail(email)) {
            return callback('邮箱地址不合法');
        }
        return callback(null, '新的随机密码已经发送到您的邮箱，请查收邮件。');
    };

}(mui, window.app = {}));


// 60s倒计时
var wait=60;
var flag =true;
function time(o) {
    if (wait == 0) {
        o.removeAttribute("disabled");
        o.innerHTML="发送验证码";
        wait = 60;
        flag=true;
    } else {
        flag = false;
        o.setAttribute("disabled", true);
        o.innerHTML= wait + " s";
        wait--;
        setTimeout(function () {
                time(o)
            },
            1000)
    }
}

mui.ready(function () {
    // 倒计时
    mui(".mui-row").on('tap', "#sends", function () {
        if(flag){
            time(this);
            console.log("11")
        }else{

            console.log("22")
        }
    })
    // 修改密码
    mui("#submit")[0].addEventListener('tap',function () {
        var phone = mui("#phone")[0].value;
        var code = mui("#code")[0].value;
        var pass = mui("#pass")[0].value;
        var loginInfo = {
            phone:phone,
            code:code,
            pass:pass,
        };
        console.log('loginInfo',loginInfo)
        app.change(loginInfo,function (text) {
            mui.alert(text);
        });
    });
});





